<template>
  <el-form :model="form" label-width="100px" class="kxz-userSuggest__dialogForm">
    <el-row :gutter="20">
      <el-col :span="10">
        <el-form-item label="用户名：">
          <el-input  v-model="Puname" readonly class="noborder"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="10">
        <el-form-item label="提交时间：">
          <el-input  v-model="Ptime" readonly class="noborder submitTime"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-form-item label="建议内容：">
      <el-input type="textarea" v-model="Psuggest" readonly class="noborder"></el-input>
    </el-form-item>
    <el-form-item label="回复内容：">
      <el-input type="textarea" v-model="form.content"></el-input>
    </el-form-item>
    <el-form-item label="图片：">
      <span @click="$emit('onopenDialogImg',Pimg)" class="open" v-if="Pimg">查看</span>
    </el-form-item>
    <el-form-item label="类型" >
      <el-select v-model="form.type.value" placeholder="请选择类型">
        <el-option v-for="(item,index) in form.type.opts" :key="index" :label="item.label" :value="item.value">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="handleSubmit()">提交</el-button>
    </el-form-item>
  </el-form>
</template>

<script>

export default {
  props:{
    Puname:String,
    Ptime:String,
    Psuggest:String,
    Pimg:String,
    Pid:[String,Number],
    Pcontent:String,
    Ptval:[String],
  },
  data(){
    const content = this.Pcontent
    console.log('Ptval:',this.Ptval)
    const Ptval = this.Ptval === ''? '' : this.Ptval === '产品' ? 0 : 1
    return {
      form:{
        content,
        type:{
          value:Ptval,
          opts:[
            {value:0, label:'产品'},
            {value:1, label:'客服'},
          ]
        }
      }
    }
  },
  watch:{
    Pcontent(val){
      this.form.content = val
    },
    Ptval(val){
      this.form.type.value = val
    },
  },
  methods:{
    handleSubmit(){
      const {content,type} = this.form
      if(content === ''){
        this.$toast({
          message:'回复内容不能为空'
        })
        return
      }
      if(type.value === ''){
        this.$toast({
          message:'类型不能为空'
        })
        return
      }
      this.postReplyContent()
    },
    async postReplyContent(){
      const {content,type} = this.form
      // console.log('content,type:', content,type)
      // return
      try{
        const {data} = await this.$get(this,{
          api:'manage/submitSuggest.do',
          data:{
            cReply: content,
            fType:type.value,
            id:this.Pid,
          }
        })
        if(data.state === 0 && data.content){
          this.$toast({
            message:'提交成功'
          })
          this.$emit('oncloseDialogForm','submit')
          return
        }
        this.$warn(data.message)
      }catch(e){
        this.$warn('系统manage/submitSuggest.do接口报错')
      }
    }
  }
}
</script>

<style lang="scss">
.kxz-userSuggest__dialogForm{
  .noborder{
     input,textarea{
      border:none;
    }
    &.submitTime{
      input{
        width:200px;
      }
    }
  }
  .open{
    // display: inline-block;
    // width:100%;
    // height:20px;
    color:#20a0ff;
    // text-overflow:ellipsis;
    // white-space:nowrap;
    cursor: pointer;
  }
}
</style>

